package pendotech.com.pendootg;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import pendotech.com.pendootg.bean.Account;
import pendotech.com.pendootg.callback.MCallback;
import pendotech.com.pendootg.mvc.MvcModel;


public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

    private EditText input_et;
    private Button search_btn;
    private TextView result_tv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        input_et = findViewById(R.id.input_et);
        search_btn = findViewById(R.id.search_btn);
        result_tv = findViewById(R.id.result_tv);

        search_btn.setOnClickListener(this);

        mvcModel = new MvcModel();


    }

    private String getInputContent() {
        return input_et.getText().toString();
    }

    private void showSuccessMsg(Account account) {
        result_tv.setText(account.getName() + "--年龄：" + account.getAge());
    }

    private void showFailMsg() {
        result_tv.setText("查无此人~");
    }


    private MvcModel mvcModel;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.search_btn:

                mvcModel.getAccountData(getInputContent(), new MCallback() {
                    @Override
                    public void onSuccess(Account account) {
                        showSuccessMsg(account);
                    }

                    @Override
                    public void onFail() {
                        showFailMsg();
                    }
                });
                break;
        }
    }
}
